//
// Created by 62660 on 2022-02-25.
//

#ifndef WEBSERVER_THREADPOLL_H
#define WEBSERVER_THREADPOLL_H
#include <vector>
#include <queue>
#include <mutex>
#include <thread>
#include <condition_variable>
#include <functional>

class ThreadPoll {
private:
    std::vector<std::thread> threadsVec;
    std::queue<std::function<void()>> tasksQueue;
    std::mutex tasks_mtx;
    std::condition_variable cond_variable;
    bool stop;
public:
    ThreadPoll(int size = 10);  // 默认size最好设置为std::thread::hardware_concurrency()
    ~ThreadPoll();
    void add(std::function<void()>);
};


#endif //WEBSERVER_THREADPOLL_H
